
class Aio::Module::OutputStyle::BriefSn < Aio::Module::OutputStyle

  include Aio::Ui::Verbose
  include Aio::Device

  def initialize
    super({
      :author		=> "Elin",
      :description	=> "这个模块是用来生成简单的设备名称，型号与序列号的文档",
      :file_suffix	=> "txt",
    })

    @report = []

  end

  def generate
    file = File.new(output_file, "w+")

    device_manager.devices.each_key do |device_name|
      device_klass = device_manager[device_name]

      generate_biref(device_klass)
    end

    file.write(@report.join("\n"))
  ensure
    file.close
  end

  def generate_biref(klass)
    hash = {}
    hash[:name] =  klass.device_name
    hash[:device_model] = klass.device_info[:device_model]
    hash[:device_factory] = klass.device_type
    hash[:inventory] = klass.inventory

    set_list(hash)
  end

  def set_list(hash)
    inv = []
    hash[:inventory].each do |info|
      inv << info[:sn]
    end
    inv_str = format("[%s]", inv.join(' '))

    str = format("%20s | %s %s| %s", hash[:name], hash[:device_factory], hash[:device_model], inv_str)
    @report << str
  end
end

